<template>
  <div class="mask">
    <div class="mask-item" @click="close"></div>
    <div class="nso">
      <div class="nso-title">社会组织数量</div>
      <div class="nso-line">
        <img src="@/assets/images/popup/1.png" alt="" />
      </div>
      <div class="nso-content">
        <div class="nso-content-tab">
          <div
            :class="
              index === current
                ? 'nso-content-tab-item nso-content-tab-item-ac'
                : 'nso-content-tab-item'
            "
            v-for="(it, index) in leftDat"
            @click="setCurrent(index)"
          >
            {{ it.shortAddress }}
          </div>
        </div>
        <div class="nso-content-c" v-if="leftDat.length > 0">
          <div class="nso-content-c-title">
            {{ leftDat[current].shortAddress }}共 {{ list.length }} 个社会组织
          </div>
          <div class="nso-content-c-teble" v-loading="loading">
            <table>
              <thead>
                <tr>
                  <td width="15%">
                    <div>序号</div>
                  </td>
                  <td width="75%"><div>社会组织名称</div></td>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(it, index) in list">
                  <td>
                    <div>
                      {{ index + 1 }}
                    </div>
                  </td>
                  <td>
                    <div>{{ it.orgName }}</div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import { areaCount, sorgInfoByArea } from '@/api/spotCheck/spotCheck'

const props = defineProps(['current'])
const emits = defineEmits(['close'])

watch(()=>props.current, val => {
  current.value = val
})

const current = ref(0)

const leftDat = ref([])
onMounted(() => {
  areaCount().then((res) => {
    leftDat.value = res.data.filter(i=> i.shortAddress != '双水镇')
    params.value.area = leftDat.value[0].shortAddress
    init()
  })
})

const close = () => {
  emits('close')
}
const setCurrent = (e) => {
  current.value = e
  params.value.area = leftDat.value[current.value].shortAddress
  init()
}
const params = ref({
  area: ''
})
const loading = ref(false)
const list = ref([])
const init = () => {
  loading.value = true
  sorgInfoByArea({ area: params.value.area })
    .then((res) => {
      list.value = res.data
    })
    .finally(() => {
      loading.value = false
    })
}
</script>

<style scoped lang="scss">
.mask {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
  .mask-item {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 99;
  }
}
.nso {
  width: 8rem;
  height: 6.5rem;
  position: absolute;
  z-index: 9;
  top: 1.8rem;
  left: 50%;
  transform: translateX(-50%);
  background-image: url('@/assets/images/popup/bg.png');
  background-size: 100% 100%;
  z-index: 100;
  .nso-title {
    width: 100%;
    text-align: center;
    font-size: 0.3rem;
    height: 0.635rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 400;
    font-size: 0.27rem;
    color: #ffffff;
  }
  .nso-line {
    width: 100%;
    height: 3px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .nso-content {
    width: 100%;
    height: calc(100% - 0.635rem - 3px - 8px);
    margin-top: 4px;
    display: flex;
    .nso-content-tab {
      width: 2.478rem;
      height: 100%;
      overflow-y: scroll;
      border-right: 1px solid #3486da;
      .nso-content-tab-item {
        width: 100%;
        height: 0.625rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        line-height: 0.625rem;
        text-align: center;
        font-family: CN, CN;
        font-weight: 400;
        font-size: 0.208rem;
        color: #b8bbcf;
        cursor: pointer;
        position: relative;
      }
      .nso-content-tab-item::after {
        width: 90%;
        content: '';
        height: 1px;
        background: #3e5294;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
      .nso-content-tab-item-ac {
        background-image: url('@/assets/images/popup/dj.png');
        background-size: 100% 100%;
      }
      .nso-content-tab-item:hover {
        background-image: url('@/assets/images/popup/dj.png');
        background-size: 100% 100%;
      }
    }
    .nso-content-tab::-webkit-scrollbar {
      display: none; /* 隐藏滚动条 */
    }
    .nso-content-c {
      min-width: 0;
      flex: 1;
      box-sizing: border-box;
      padding: 0.208rem 0.291rem;
      .nso-content-c-title {
        width: 100%;
        font-family: CN, CN;
        font-weight: 400;
        font-size: 0.1875rem;
        color: #b8bbcf;
        margin-bottom: 0.208rem;
      }
    }
  }
}
.nso-content-c-teble {
  width: 100%;
  height: calc(100% - 0.35rem);
  overflow-y: scroll;
  .table-title {
    font-weight: 500;
    font-size: 0.27rem;
    color: #333333;
    text-align: center;
    margin-bottom: 30px;
  }

  table {
    border-collapse: collapse;
    width: 100%;
    margin-top: 8px;
  }
  table {
    border: 2px double #3486da; /* 外边框的双边框样式 */
  }
  th,
  td {
    //border: 1px solid #3486da;
    padding: 1px;
    & > div {
      height: 100%;
      border: 1px solid #2669c0;
    }
  }
  thead {
    background: rgba(52, 134, 218, 0.2);
  }
  th,
  td {
    min-height: 0.458rem;
    text-align: center;
    font-size: 0.1875rem;
    color: #b8bbcf;
  }
  td {
    & > div {
      padding: 0.125rem 6px;
    }
  }
  th {
    background: rgba(52, 134, 218, 0.8) !important;
  }
}
.nso-content-c-teble::-webkit-scrollbar {
  display: none; /* 隐藏滚动条 */
}
</style>
